using System;
using System.Runtime.InteropServices;

namespace GoldStone.ICTSplit {
    public enum NatureRequired {
        WithoutNature = 0,
        OnlyFirstTag = 1,
        AllTag = 2
    } ;

    public enum OutputFormat {
        PKU = 0,
        _973 = 1,
        XML = 2
    } ;

    public struct ClasInit {
        public String DictionaryFolder;
        public NatureRequired Nature;
        public OutputFormat OutputFormat;

        public ClasInit(String dictionaryFolder) {
            DictionaryFolder = dictionaryFolder;
            Nature = NatureRequired.WithoutNature;
            OutputFormat = OutputFormat.PKU;
        }
    }

    public class ICTSplitLib {
        [DllImport("ICTCLAS.dll")]
        private static extern void Initialize(ClasInit initParam);

        [DllImport("ICTCLAS.dll")]
        private static extern void SetNatureRequired(NatureRequired nature);

        [DllImport("ICTCLAS.dll")]
        private static extern String ParagraphProcessing(String input);

        public ICTSplitLib(ClasInit initParams) {
            Initialize(initParams);
        }

        public String Split(String text) {
            return SplitWithNatureInfo(text, NatureRequired.WithoutNature);
        }

        public String SplitWithNatureInfo(String text, NatureRequired nature) {
            if (String.IsNullOrEmpty(text)) {
                return String.Empty;
            }
            SetNatureRequired(nature);
            return ParagraphProcessing(text).Trim();
        }
    }
}